<?php
	include("../include/init.php");//将配置文件全部加载进来
	include("../include/check_login.php");//登录

	$insert = new sql_class("admin");

	$admin_id = isset($_GET['admin_id']) ? $_GET['admin_id'] : 0;

	if(!$admin_id){//判断有无该id
		show_msg("请重新选择","admin_list.php");
		exit;
	}

	$where = "admin_id = $admin_id";
	$admin_one = $insert->select($where)->getOne();//查询该id的信息

	if($_POST){
		$data = array(
					"admin_name"=>trim($_POST['admin_name']),//接收传过来的信息
				);
		if(!empty($_POST['admin_pwd'])){
			$data['admin_pwd'] = md5($_POST['admin_pwd']);//判断密码输入框是否有值，有值才更新，无值不更新
		}

		if($_FILES['admin_img']['size'] > 0){//图片上传
			$path = DIR."/uploads/";
			$filename = uploads("admin_img",1048576,$path);
			$data['admin_img'] = 'uploads/'.$filename;
		}
		
		$where = "admin_id = $admin_id";
		$insert_id = $insert->update($data,$where);
		if($insert_id){
			show_msg("修改管理员成功","admin_list.php");
			exit;
		}else{
			show_msg("修改管理员失败","admin_edit.php?admin_id = $admin_id");
			exit;
		}
	}
	

	$smarty->assign("admin_one",$admin_one);
	$smarty->display("admin/admin_edit.html");//连接index.html



?>